package com.weiyi.servlet02;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
 * 
 * @description 处理乱码问题
 * @author 惟一
 * @date 2020年6月26日下午5:59:34
 */
@WebServlet("/encoding")
public class EncodingDemo extends HttpServlet{
	
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		String parameter = req.getParameter("nameGet");
	//	若工程的编码方式为ISO-8859-1，可通过如下方式解决乱码问题
	//	parameter = new String(parameter.getBytes("ISO-8859-1"),"UTF-8");		
		System.out.println("GET: " + parameter);
		
	}
	
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		req.setCharacterEncoding("UTF-8");
		String parameter = req.getParameter("namePost");
		System.out.println("POST: " + parameter);
		
	}
}
